from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views.order_views import OrderViewSet
from .views.customer_views import CustomerViewSet
from .views.product_views import ProductViewSet
from .views.expiration_views import ExpirationViewSet
from .views.host_order_views import HostOrderViewSet

router = DefaultRouter()
router.register(r'orders', OrderViewSet, basename='order')
router.register(r'customers', CustomerViewSet, basename='customer')
router.register(r'products', ProductViewSet, basename='product')
router.register(r'expirations', ExpirationViewSet, basename='expiration')
router.register(r'host-orders', HostOrderViewSet, basename='host-order')

# 已经通过router自动注册的URL:
# /api/omm/orders/import_template/ - 获取订单导入模板
# /api/omm/orders/import/ - 导入订单数据
# /api/omm/host-orders/import_template/ - 获取主机出租订单导入模板
# /api/omm/host-orders/import_data/ - 导入主机出租订单数据
# /api/omm/expirations/export/ - 导出产品到期数据
# /api/omm/expirations/import_template/ - 获取产品到期导入模板
# /api/omm/expirations/import_data/ - 导入产品到期数据

urlpatterns = [
    path('', include(router.urls)),
    # 添加明确的路由映射，确保路径正确
    path('host-orders/import_template/', HostOrderViewSet.as_view({'get': 'import_template'}), name='host-order-import-template'),
    path('host-orders/import_data/', HostOrderViewSet.as_view({'post': 'import_data'}), name='host-order-import-data'),
    # 明确添加到期产品导出的URL映射
    path('expirations/export/', ExpirationViewSet.as_view({'get': 'export'}), name='expiration-export'),
    # 添加到期产品导入相关URL映射
    path('expirations/import_template/', ExpirationViewSet.as_view({'get': 'import_template'}), name='expiration-import-template'),
    path('expirations/import_data/', ExpirationViewSet.as_view({'post': 'import_data'}), name='expiration-import-data'),
    # 添加年度收入API路由
    path('orders/sales/yearly-revenue/', OrderViewSet.as_view({'get': 'get_yearly_revenue'}), name='yearly-revenue'),
]
